(function(t){if(BX.TagsWindowArea)return;BX.TagsWindowArea=function(t,e){this.objId=++BX.TagsWindowArea.__conter;this.maxTagId=0;this.mode=BX.TagsWindowArea.mode.defaultMode;this.tagsContainer=BX.create("div",{props:{className:"popup-tags-content"+(BX.browser.IsIE()?" popup-tags-content-ie":"")},html:'<table cellspacing="0"> \t\t\t\t<tr><td class="popup-tags-left-top-cell"></td><td class="popup-tags-right-top-cell"></td></tr> \t\t\t\t<tr><td colspan="2" class="popup-tags-middle-cell"><div class="popup-window-hr"><i></i></div></td></tr> \t\t\t\t<tr><td class="popup-tags-left-bottom-cell"></td><td class="popup-tags-right-bottom-cell"></td></tr></table>'});this.newTagTexbox=BX.create("input",{props:{type:"text",value:""},attrs:{autocomplete:"off"},events:{keydown:BX.proxy(this.__onKeydownTextbox,this),keyup:BX.proxy(this.__onKeyupTextbox,this)}});this.newTagButton=BX.create("div",{props:{className:"popup-tags-add-button"},attrs:{title:BX.message("TAGS_BUTTON_ADD_TITLE")},events:{click:BX.proxy(this.__onAddButtonClick,this)}});this.content=BX.create("div",{props:{className:"popup-tags-window",id:"task-tags-content"},children:[BX.create("div",{props:{className:"popup-tags-create-new"},children:[BX.create("div",{props:{className:"popup-tags-textbox"},children:[this.newTagTexbox]}),this.newTagButton]}),BX.create("div",{props:{className:"popup-window-hr"},children:[BX.create("I",{})]}),BX.create("div",{props:{className:"popup-tags-content-wrapper"},children:[this.tagsContainer]})]});var i=this.tagsContainer.getElementsByTagName("td");this.leftTopCell=i[0];this.rightTopCell=i[1];this.middleCell=i[2];this.leftBottomCell=i[3];this.rightBottomCell=i[4];this.tags=[];this.renamedTags=[];this.deletedTags=[];for(var o=0,s=t?t.length:0;o<s;o++)this.addTag(t[o]);if(e&&e.events){for(var a in e.events)BX.addCustomEvent(this,a,e.events[a])}};BX.TagsWindowArea.__conter=0;BX.TagsWindowArea.tagPosition={leftTop:1,rightTop:2,leftBottom:3,rightBottom:4};BX.TagsWindowArea.mode={defaultMode:1,highlightMode:2,editMode:3};BX.TagsWindowArea.prototype.addTag=function(t){if(!t.name||!BX.type.isString(t.name))return null;t.name=BX.util.trim(t.name);if(t.name.length<1||this.indexOfTagName(t.name)>-1)return null;t.id=t.id?t.id:++this.maxTagId;t.selected=t.selected&&t.selected===true?true:false;t.markToDelete=false;t.position=null;t.editTextbox=null;this.tags.unshift(t);return t};BX.TagsWindowArea.prototype.removeTag=function(t){var e=this.indexOfTag(t);if(e>-1)this.tags=BX.util.deleteFromArray(this.tags,e);return e>-1};BX.TagsWindowArea.prototype.selectTag=function(t,e){var i=this.indexOfTag(t);if(i>-1)this.tags[i].selected=!!e;return i>-1};BX.TagsWindowArea.prototype.selectAllTags=function(t,e){var i,o;t=!!t;if(BX.type.isArray(e)){for(i=0,o=this.tags.length;i<o;i++)this.tags[i].selected=BX.util.in_array(this.tags[i],e)?t:!t}else{for(i=0,o=this.tags.length;i<o;i++)this.tags[i].selected=t}};BX.TagsWindowArea.prototype.indexOfTag=function(t){var e=-1;for(var i=0,o=this.tags.length;i<o;i++){if(this.tags[i]==t){e=i;break}}return e};BX.TagsWindowArea.prototype.indexOfTagName=function(t){var e=-1;for(var i=0,o=this.tags.length;i<o;i++){if(this.tags[i].name.toLowerCase()==t.toLowerCase()){e=i;break}}return e};BX.TagsWindowArea.prototype.getSelectedTags=function(){var t=[];for(var e=0,i=this.tags.length;e<i;e++){if(this.tags[e].selected)t.push(this.tags[e])}return t};BX.TagsWindowArea.prototype.getTags=function(){return this.tags};BX.TagsWindowArea.prototype.sortTags=function(){this.tags.sort(this.__sortTags)};BX.TagsWindowArea.prototype.__sortTags=function(t,e){var i=t.name.toLowerCase();var o=e.name.toLowerCase();if(i<o)return-1;else if(i>o)return 1;return 0};BX.TagsWindowArea.prototype.setMode=function(t){if(t==BX.TagsWindowArea.mode.defaultMode||t==BX.TagsWindowArea.mode.highlightMode||t==BX.TagsWindowArea.mode.editMode)this.mode=t};BX.TagsWindowArea.prototype.redraw=function(t,e){if(t)this.setMode(t);if(this.mode==BX.TagsWindowArea.mode.highlightMode){this._disableAddButton(false);this._renderHighlight(e)}else if(this.mode==BX.TagsWindowArea.mode.editMode){this._disableAddButton(true);this._render(e)}else{this._disableAddButton(false);this._render(e)}};BX.TagsWindowArea.prototype._disableAddButton=function(t){if(!!t){BX.addClass(this.newTagButton,"popup-tags-add-button-disabled");this.newTagTexbox.disabled=true}else{BX.removeClass(this.newTagButton,"popup-tags-add-button-disabled");this.newTagTexbox.disabled=false}};BX.TagsWindowArea.prototype._render=function(t){this.rightTopCell.innerHTML=this.leftTopCell.innerHTML=this.rightBottomCell.innerHTML=this.leftBottomCell.innerHTML="";var e=0;var i=0;for(var o=0,s=this.tags.length;o<s;o++){var a=this.createTagItem(this.tags[o]);if(this.tags[o].selected){if(e<2)BX.addClass(a,"popup-tags-item-first");if(e%2){this.tags[o].position=BX.TagsWindowArea.tagPosition.rightTop;this.rightTopCell.appendChild(a)}else{this.tags[o].position=BX.TagsWindowArea.tagPosition.leftTop;this.leftTopCell.appendChild(a)}e++}else{if(i<2)BX.addClass(a,"popup-tags-item-first");if(i%2){this.tags[o].position=BX.TagsWindowArea.tagPosition.rightBottom;this.rightBottomCell.appendChild(a)}else{this.tags[o].position=BX.TagsWindowArea.tagPosition.leftBottom;this.leftBottomCell.appendChild(a)}i++}}this.__resize(e,i)};BX.TagsWindowArea.prototype.__resize=function(t,e){this.tagsContainer.style.height="auto";this.tagsContainer.style.overflowY="visible";var i=false;if(i||document.documentMode&&document.documentMode<=7)this.tagsContainer.style.paddingRight="0";if(t==0||e==0){this.middleCell.style.height="1px";this.middleCell.style.visibility="hidden"}else{this.middleCell.style.height="19px";this.middleCell.style.visibility="visible"}if(this.tagsContainer.offsetHeight>200){this.tagsContainer.style.height="200px";this.tagsContainer.style.overflowY="scroll";if(i||document.documentMode&&document.documentMode<=7)this.tagsContainer.style.paddingRight="20px"}else if(t==0&&e==0||this.tagsContainer.offsetHeight<40)this.tagsContainer.style.height="40px"};BX.TagsWindowArea.prototype._renderHighlight=function(t){var e=t.word&&BX.type.isString(t.word)?BX.util.trim(t.word):"";if(e&&e.lastIndexOf(",")>-1)e=BX.util.trim(e.substr(e.lastIndexOf(",")+1));var i=null;this.leftBottomCell.innerHTML=this.rightBottomCell.innerHTML="";for(var o=0,s=false,a=false,n=this.tags.length;o<n;o++){var r=this.tags[o];if(!r.position)continue;var d=this.createTagItem(r,e);if(r.position==BX.TagsWindowArea.tagPosition.leftBottom){if(!s)BX.addClass(d,"popup-tags-item-first");s=true;this.leftBottomCell.appendChild(d)}else if(r.position==BX.TagsWindowArea.tagPosition.rightBottom){if(!a)BX.addClass(d,"popup-tags-item-first");a=true;this.rightBottomCell.appendChild(d)}if(i===null&&BX.hasClass(d,"popup-tags-item-highlight-mode"))i=d}if(this.tagsContainer.offsetHeight==200&&i!==null)this.tagsContainer.scrollTop=i.offsetTop};BX.TagsWindowArea.prototype.saveEditTags=function(){if(this.mode!=BX.TagsWindowArea.mode.editMode)return;var t=[];for(var e=0,i=this.tags.length;e<i;e++){var o=this.tags[e];if(o.markToDelete){this.deletedTags.push(o);continue}if(o.editTextbox){var s=BX.util.trim(o.editTextbox.value);if(BX.type.isNotEmptyString(s)&&s!=o.name){this.renamedTags[o.name]=s;o.name=s}}t.push(o)}this.tags=t};BX.TagsWindowArea.prototype.cancelEdit=function(){if(this.mode!=BX.TagsWindowArea.mode.editMode)return;for(var t=0,e=this.tags.length;t<e;t++)this.tags[t].markToDelete=false};BX.TagsWindowArea.prototype.focusTextbox=function(){this.newTagTexbox.value="";BX.focus(this.newTagTexbox)};BX.TagsWindowArea.prototype.addTextboxTag=function(){if(this.mode==BX.TagsWindowArea.mode.editMode)return null;var t=BX.util.trim(this.newTagTexbox.value);if(t.length<1)return null;var e=[];var i=t.split(",");for(var o=0;o<i.length;o++){var s=BX.util.trim(i[o]);var a=this.indexOfTagName(s);if(a<0){var n=this.addTag({name:s,selected:true});if(n!=null)e.push(n)}else this.tags[a].selected=true}BX.onCustomEvent(this,"onTagCreate",[e]);this.redraw(BX.TagsWindowArea.mode.defaultMode);setTimeout(BX.proxy(this.focusTextbox,this),0);return e};BX.TagsWindowArea.prototype.__onKeydownTextbox=function(e){if(!e)e=t.event;if(this.mode==BX.TagsWindowArea.mode.editMode)return;var i=e.keyCode?e.keyCode:e.which?e.which:null;if(i==13)this.addTextboxTag()};BX.TagsWindowArea.prototype.__onKeyupTextbox=function(e){if(!e)e=t.event;if(this.mode==BX.TagsWindowArea.mode.editMode)return;var i=e.keyCode?e.keyCode:e.which?e.which:null;if(i!==13)this.redraw(BX.TagsWindowArea.mode.highlightMode,{word:this.newTagTexbox.value})};BX.TagsWindowArea.prototype.__onAddButtonClick=function(t){this.addTextboxTag()};BX.TagsWindowArea.prototype.__onTagClick=function(t){this.obj.selectTag(this.tag,!this.tag.selected);BX.onCustomEvent(this.obj,"onTagClick",[this.tag]);this.obj.focusTextbox()};BX.TagsWindowArea.prototype.__onTagDelete=function(t){this.tag.markToDelete=true;if(this.tag.editTextbox){var e=this.tag.editTextbox.parentNode.parentNode;if(BX.hasClass(e,"popup-tags-item-first")){var i=e.parentNode.childNodes;if(i.length>1)BX.toggleClass(i[1],"popup-tags-item-first");i=null}BX.remove(e)}var o=0;var s=0;for(var a=0,n=this.obj.tags.length;a<n;a++){if(this.obj.tags[a].markToDelete===true)continue;if(this.obj.tags[a].selected)o++;else s++}this.obj.__resize(o,s);BX.PreventDefault(t)};BX.TagsWindowArea.prototype.__onTagTextboxBlur=function(t){var e=BX.util.trim(this.tag.editTextbox.value);if(!BX.type.isNotEmptyString(e))this.tag.editTextbox.value=this.tag.name};BX.TagsWindowArea.prototype.__wordwrap=function(t,e,i,o){var s=o!==false;var a=t.split(" ");for(var n=0;n<a.length;n++){var r=a[n];if(r.length>e){var d=r.match(new RegExp(".{0,"+e+"}","g"));for(var l=0;l<d.length;l++)d[l]=s?BX.util.htmlspecialchars(d[l]):d[l];a[n]=d.join(i)}else a[n]=s?BX.util.htmlspecialchars(a[n]):a[n]}return a.join(" ")};BX.TagsWindowArea.prototype.__highlight=function(t,e){var i=t.name;i=this.__wordwrap(i,13,",",false);for(var o=0,s=0;o<i.length&&s<e.length;o++){if(i.charAt(o)==",")continue;s++}i='<span class="popup-tags-item-highlighted">'+BX.util.htmlspecialchars(i.substr(0,o))+"</span>"+BX.util.htmlspecialchars(i.substr(o));return i.replace(new RegExp(",","g"),"&#8203;")};BX.TagsWindowArea.prototype.createTagItem=function(t,e){var i=t.name;var o="popup-tags-item-"+this.objId+"-"+t.id;if(this.mode==BX.TagsWindowArea.mode.editMode){var s=BX.create("input",{props:{className:"popup-tags-item-texbox",type:"text",value:i},events:{blur:BX.proxy(this.__onTagTextboxBlur,{obj:this,tag:t})}});t.editTextbox=s;return BX.create("div",{props:{className:"popup-tags-item popup-tags-item-edit-mode"},children:[BX.create("div",{props:{className:"popup-tags-item-edit-mode-wrapper"},children:[s,BX.create("a",{props:{className:"popup-tags-item-delete-icon",href:""},attrs:{title:BX.message("TAGS_BUTTON_DELETE_TITLE")},events:{click:BX.proxy(this.__onTagDelete,{obj:this,tag:t})}})]})]})}else{var a=false;if(e&&!t.selected&&e.length<=i.length&&i.substr(0,e.length).toLowerCase()===e.toLowerCase()){a=true;i=this.__highlight(t,e)}else i=this.__wordwrap(i,13,"&#8203;");var n="popup-tags-item"+(a?" popup-tags-item-highlight-mode":" popup-tags-item-default-mode");if(BX.browser.IsIE())n+=" popup-tags-item-ie";return BX.create("div",{props:{className:n},children:[BX.create("input",{props:{className:"popup-tags-item-checkbox",type:"checkbox",id:o,checked:t.selected,defaultChecked:t.selected},events:{click:BX.proxy(this.__onTagClick,{obj:this,tag:t})}}),BX.create("label",{props:{htmlFor:o},html:i})]})}}})(window);(function(t){var e={};BX.TagsWindow={create:function(t,o,s,a){if(!e[t])e[t]=new i(t,o,s,a);return e[t]}};var i=function(t,e,i,s){this.windowArea=new BX.TagsWindowArea(i,{events:{onTagClick:BX.proxy(this.UpdateTagLine,this),onTagCreate:BX.proxy(this.UpdateTagLine,this)}});this.selectButton=new BX.PopupWindowButton({text:BX.message("TAGS_BUTTON_OK"),className:"popup-window-button-create",events:{click:BX.proxy(this.onSelectButtonClick,this)}});this.cancelButton=new BX.PopupWindowButtonLink({text:BX.message("TAGS_BUTTON_CANCEL"),className:"popup-window-button-link-cancel",events:{click:BX.proxy(this.onCancelButtonClick,this)}});this.editButton=null;s.editMode=s&&s.editMode===false?false:true;if(s.editMode)this.editButton=new o({events:{click:BX.proxy(this.onEditButtonClick,this)}});this.popupWindow=BX.PopupWindowManager.create(t,e,{content:"",buttons:[this.selectButton,this.cancelButton,this.editButton],closeByEsc:true,events:{onPopupFirstShow:BX.proxy(function(t){t.setContent(this.windowArea.content)},this),onPopupShow:BX.proxy(function(t){this.windowArea.sortTags();t.popupContainer.style.display="block";this.windowArea.redraw(BX.TagsWindowArea.mode.defaultMode);this.UpdateTagLine()},this),onAfterPopupShow:BX.proxy(function(t){this.windowArea.focusTextbox()},this)}});if(s&&s.events){for(var a in s.events)BX.addCustomEvent(this,a,s.events[a])}this.initSelectedTags=null};i.prototype.onSelectButtonClick=function(t){if(this.windowArea.mode==BX.TagsWindowArea.mode.editMode){this.windowArea.saveEditTags();this.windowArea.redraw(BX.TagsWindowArea.mode.defaultMode);this.UpdateButtons();this.UpdateTagLine();BX.onCustomEvent(this,"onSaveButtonClick",[this])}else{this.windowArea.addTextboxTag();this.popupWindow.close();BX.onCustomEvent(this,"onSelectButtonClick",[this])}};i.prototype.onCancelButtonClick=function(t){if(this.windowArea.mode==BX.TagsWindowArea.mode.editMode){this.windowArea.cancelEdit();this.windowArea.redraw(BX.TagsWindowArea.mode.defaultMode);this.UpdateButtons();this.windowArea.focusTextbox();BX.onCustomEvent(this,"onCancelButtonClick",[this])}else{if(this.initSelectedTags!=null)this.windowArea.selectAllTags(true,this.initSelectedTags);this.UpdateTagLine();this.popupWindow.close();BX.onCustomEvent(this,"onCancelButtonClick",[this])}BX.PreventDefault(t)};i.prototype.onEditButtonClick=function(t){if(this.windowArea.mode!=BX.TagsWindowArea.mode.editMode){this.windowArea.redraw(BX.TagsWindowArea.mode.editMode);this.UpdateButtons();BX.onCustomEvent(this,"onEditButtonClick",[this])}BX.PreventDefault(t)};i.prototype.showPopup=function(){this.initSelectedTags=this.windowArea.getSelectedTags();this.popupWindow.show()};i.prototype.UpdateButtons=function(){for(var t=0;t<this.popupWindow.buttons.length;t++){var e=this.popupWindow.buttons[t];if(e==this.selectButton)this.selectButton.setName(this.windowArea.mode==BX.TagsWindowArea.mode.editMode?BX.message("TAGS_BUTTON_SAVE"):BX.message("TAGS_BUTTON_OK"));else if(e==this.cancelButton)this.cancelButton.setName(this.windowArea.mode==BX.TagsWindowArea.mode.editMode?BX.message("TAGS_BUTTON_DISCARD"):BX.message("TAGS_BUTTON_CANCEL"));else if(e==this.editButton){if(this.windowArea.mode==BX.TagsWindowArea.mode.editMode)this.editButton.setClassName("popup-tags-button-edit-pressed");else this.editButton.setClassName("")}}};i.prototype.UpdateTagLine=function(){BX.onCustomEvent(this,"onUpdateTagLine",[this])};var o=function(t){o.superclass.constructor.apply(this,arguments);this.buttonNode=BX.create("a",{props:{className:"popup-tags-button-edit",id:this.id,href:""},attrs:{title:BX.message("TAGS_BUTTON_EDIT_TITLE")},events:this.contextEvents});if(BX.browser.IsIE())this.buttonNode.setAttribute("hideFocus","hidefocus")};BX.extend(o,BX.PopupWindowButton)})(window);
//# sourceMappingURL=core_tags.map.js